<?php

/**
 * Created by PhpStorm.
 * User: shwy
 * Date: 2017/9/8
 * Time: 9:40
 * 财务审核管理相关接口
 */
class goldCheck extends CI_Controller
{


    public function __construct()
    {
        parent::__construct();
        $this->load->model('check_model');
        $this->load->model('procurement_model');
//        $this->load->model('user_model');
        $this->load->model('purchaseOrder_model');
        $this->load->model('goldCheck_model');

    }


    //供应商待办列表筛选搜索
    public function search()
    {

        $argc = [];
        if (isset($_GET['startTime']) && $_GET['startTime']) {
            $argc += [
                'createTime >' => strtotime($_GET['startTime']),
            ];
        }

        if (isset($_GET['endTime']) && $_GET['endTime']) {
            $argc += [
                'createTime <' => strtotime($_GET['endTime']),
            ];
        }

        if (isset($_GET['status']) && $_GET['status'] != '' && $_GET['status'] != 'null') {
            //0表示待审核
            //1表示已审核
            if ($_GET['status'] == 0) {
                //查询待审核的
                $argc += [
                    'status ' => 1
                ];
            } else {
                //查询已审核的
                $argc += [
                    'status !=' => 1
                ];
            }

        }

        if (isset($_GET['search']) && $_GET['search'] != '') {
            $searchArg = [
                'field' => 'name',
                'arg' => $_GET['search'],
                'side' => 'both'
            ];
        } else {
            $searchArg = '';
        }


        $page_num = $this->config->item('fenye')['pageNum']; //每页的数据
        $start_position = ''; //初始数据
        $page = ($this->input->get('page')); //获取页码数量
        $type = isset($_GET['type']) ? $_GET['type'] : 2; //类型，1为进货单，2为抄送的单据
        if (!$page) {
            $num = 1;
            $start_position = ($num - 1) * $page_num;
        } else {
            $start_position = ($page - 1) * $page_num;
        }

        if (!$argc) {
            $argc = [];
        }


//        print_r($type);
//        die;


        if($type == 1){
            if ($searchArg) {
                $data = $this->purchaseOrder_model->search('*', $argc, $searchArg, $page_num, $start_position);
            } else {
                $data = $this->purchaseOrder_model->page('purchaseOrder', $argc, $page_num, $start_position);
            }

            if ($data[0]) {
                foreach ($data[0] as $k => $v) {
                    $data[0][$k]['payInfo'] = json_decode($v['payInfo'], true);
                }

                foreach ($data[0] as $k2 => $v2) {
                    $last = end($data[0][$k2]['payInfo']);

//                    __logInfo('debug',json_encode($last,JSON_UNESCAPED_UNICODE));

                    switch ($last['prepay']) {
                        case 0.05:
                            $last['prepay'] = '预付款5%';
                            break;
                        case 0.10:
                            $last['prepay'] = '预付款10%';
                            break;
                        case 0.15:
                            $last['prepay'] = '预付款15%';
                            break;
                        case 0.2:
                            $last['prepay'] = '预付款20%';
                            break;
                        case 0.3:
                            $last['prepay'] = '预付款30%';
                            break;
                        case 0.4:
                            $last['prepay'] = '预付款40%';
                            break;
                        case 0.5:
                            $last['prepay'] = '预付款50%';
                            break;
                        case 0.6:
                            $last['prepay'] = '预付款60%';
                            break;
                        case 0.7:
                            $last['prepay'] = '预付款70%';
                            break;
                        case 0.8:
                            $last['prepay'] = '预付款80%';
                            break;
                        case 1:
                            $last['prepay'] = '预付款100%';
                            break;
                    }

                    $data[0][$k2]['nowPrepay'] = $last['prepay'];
                    $data[0][$k2]['nowPayMan'] = $last['payMan'];
                    $data[0][$k2]['createTime'] = date('Y-m-d',$v2['createTime']);

                    unset($data[0][$k2]['payInfo']);
                }
            }


            $data['pageNum'] = $page_num;
            $data['this_page'] = $page;
            $data['type'] = $type;


            echo json_encode($data, JSON_UNESCAPED_UNICODE);
        }else{


            if ($searchArg) {
                $data2 = $this->goldCheck_model->search('*', $argc, $searchArg, $page_num, $start_position);
            } else {
                $data2 = $this->goldCheck_model->page('goldCheck', $argc, $page_num, $start_position);
            }

            foreach ($data2[0] as $k=>$v){
                $data2[0][$k]['createTime'] = date('Y-m-d',$v['createTime']);
            }


            $data2['pageNum'] = $page_num;
            $data2['this_page'] = $page;
            $data2['type'] = $type;

            echo json_encode($data2, JSON_UNESCAPED_UNICODE);

        }


    }


}










































